﻿#region The MIT License (MIT)
// The MIT License (MIT)
// Copyright (c) 2010 - 2013 Sovacode LLC
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#endregion

using System.ComponentModel;

/* Importing namespaces */
using Sovacode.RubiksCube.Common.Attributes;

namespace Sovacode.DemoApp.ViewModel
{
    /// <summary>
    /// To use old Switch { Case } logic mark View Model class <see cref="ValidateByManagerAttribute"/> attribute with false. It will turn off Validation Manager.
    /// </summary>
    [ValidateByManager(false)]
    public sealed class SimpleValidationViewModel /*
                                                   * How to use old Switch { Case } Validation logic
                                                   * 
                                                   * If you have already a lot of objects with validation
                                                   * you can simplify move validation logic to new method Validate(string)
                                                   * 
                                                   */
        : BasicViewModel.BaseValidationViewModel
    {
        #region Overrides

        /// <summary>
        /// Validate all properties of object. You should use it in all objects with all style validation
        /// </summary>
        /// <returns>True in case if all properties of object is valid</returns>
        protected override bool Valid()
        {
            return string.IsNullOrWhiteSpace(Validate(() => Name));
        }

        /// <summary>
        /// Validation of object via <see cref="IDataErrorInfo"/>. You should you use it in all objects with old style validation.
        /// </summary>
        /// <param name="propertyName">Name of property</param>
        /// <returns>Empty string in case if property valid</returns>
        protected override string Validate(string propertyName)
        {
            /* Old Switch{Case} logic */
            switch (propertyName)
            {
                case "Name":
                    {
                        return string.IsNullOrWhiteSpace(Name) ? "Name can not be empty!" : string.Empty;
                    }
            }

            return string.Format("Unknown '{0}' property!", propertyName);
        }

        /// <summary>
        /// Gets the description file.
        /// </summary>
        /// <value>The description file.</value>
        protected override string DescriptionFile
        {
            get { return "SimpleValidationDescription.txt"; }
        }

        #endregion
    }
}